from django.views import View
from django.shortcuts import render

from .models import Chapter, ChapterText
from course.models import Course


class ChapterListView(View):

    def get(self, request, course_id):
        course = Course.objects.get(pk=course_id)
        chapters = Chapter.objects.filter(course_id=course_id)
        return render(
            request,
            'chapter/list.html',
            {
                'chapters': chapters,
                'course': course
            }
        )


class ChapterDetailView(View):
    def get(self, request, course_id, chapter_id):
        course = Course.objects.get(pk=course_id)
        chapters = Chapter.objects.filter(course_id=course_id)
        chapter_text = ChapterText.objects.get(pk=chapter_id)
        return render(
            request,
            'chapter/detail.html',
            {
                'course': course,
                'chapters': chapters,
                'chapter_text': chapter_text
            }
        )
